package course.view;

import java.awt.Color;
<<<<<<< HEAD
import java.awt.Dialog.ModalityType;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import course.controller.CourseControllerListener;
import course.po.Student;

public class StudentDialog extends JDialog{
	private static final long serialVersionUID = -421235125631385670L;
	private CourseControllerListener  courseControllerListener;
	private JButton confirmButton;
	private JPanel studentAddPanel;
	private Student student;
	private JTextField studentIdTextField;
	private JTextField studentNoTextField;
	private JTextField  studentNameTextField;
	private JTextField studentSexTextField;
	private JTextField  studentAgeTextField;
	private JTextField  studentMajorTextField;
	private JTextField studentClassNoTextField;
	private JTextField courseIdTextField;
	private JTextField  courseNameTextField;
	private JTextField  studentGradeTextField;
	public static JRadioButton radioMan;
	public static JRadioButton radioFemal;
	
	public StudentDialog(StudentJPanel owner, String title, Student student) {
		this.courseControllerListener = owner.getControllerListener();
		this.courseControllerListener.setStudentAddDialog(this);
		this.setTitle(title);
		this.student = student;
		this.add(getStudentAddPanel());
		this.setModal(true); // 设有模
		this.setModalityType(ModalityType.DOCUMENT_MODAL);//DOCUMENT_MODAL对话框阻止来自同一文档的所有顶级窗口的输入，但来自其自己的子层次结构的窗口除外。
		this.setSize(370, 530);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setVisible(true);
		this.validate();
	}

	public void closeCurrentDialog() {
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

	}

	/**
	 * 添加/修改表单面板
	 * 
	 * @return
	 */
	private JPanel getStudentAddPanel() {
		studentAddPanel = new JPanel();
		studentAddPanel.setBackground(Color.orange);
		if ("添加学生".equals(this.getTitle())) {
			radioMan = new JRadioButton("男");
			radioFemal = new JRadioButton("女");
			ButtonGroup group = new ButtonGroup();
			group.add(radioMan);
			group.add(radioFemal);
			studentIdTextField = new JTextField(30);
			studentNoTextField = new JTextField(30);
			studentNameTextField = new JTextField(30);
//			studentSexTextField = new JTextField(30);
			studentAgeTextField = new JTextField(30);
			studentAgeTextField.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
				new FunctionFrame();
			
				studentAgeTextField.setText(String.valueOf(FunctionFrame.getSqlDate()));
				}
			});
			studentMajorTextField = new JTextField(30);
			studentClassNoTextField = new JTextField(30);
			courseIdTextField = new JTextField(30);
			studentGradeTextField = new JTextField(30);
			confirmButton = new JButton("确定添加");
			confirmButton.setActionCommand("addStudentPost"); // 添加学生
		} else {
			radioMan = new JRadioButton("男");
			radioFemal = new JRadioButton("女");
			ButtonGroup group = new ButtonGroup();
			group.add(radioMan);
			group.add(radioFemal);
			studentIdTextField = new JTextField(String.valueOf(student.getStuId()), 30);
			studentNoTextField = new JTextField(student.getStuNo(), 30);
			studentNameTextField = new JTextField(student.getStuName(), 30);
//			studentSexTextField = new JTextField(student.getStuSex(), 30);
			if(student.getStuSex().contentEquals("男")) {
				radioMan.setSelected(true);
			} else {
				radioFemal.setSelected(true);
			}
			studentAgeTextField = new JTextField(String.valueOf(student.getStuAge()), 30);
			studentAgeTextField.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
				new FunctionFrame();
				studentAgeTextField.setText(String.valueOf(FunctionFrame.getSqlDate()));
				}
			});
			studentMajorTextField = new JTextField(student.getStuMajor(), 30);
			studentClassNoTextField = new JTextField(String.valueOf(student.getStuClassNo()), 30);
			courseIdTextField =  new JTextField(String.valueOf(student.getCourse().getCouId()), 30);
			studentGradeTextField = new JTextField(String.valueOf(student.getStuGrade()), 30);
			confirmButton = new JButton("确定修改");
			confirmButton.setActionCommand("updateStudentPost"); // 修改学生
		}
		confirmButton.addActionListener( courseControllerListener);
		studentAddPanel.add(new JLabel("编号"));
		studentAddPanel.add(studentIdTextField);
		studentAddPanel.add(new JLabel("学号"));
		studentAddPanel.add(studentNoTextField);
		studentAddPanel.add(new JLabel("姓名"));
		studentAddPanel.add(studentNameTextField);
		studentAddPanel.add(new JLabel("性别"));
		studentAddPanel.add(radioMan);
		studentAddPanel.add(radioFemal);
		studentAddPanel.add(new JLabel("年龄"));
		studentAddPanel.add(studentAgeTextField);
		studentAddPanel.add(new JLabel("专业"));
		studentAddPanel.add(studentMajorTextField);
		studentAddPanel.add(new JLabel("班级"));
		studentAddPanel.add(studentClassNoTextField);
		studentAddPanel.add(new JLabel("课程编号"));
		studentAddPanel.add(courseIdTextField);
//		studentAddPanel.add(new JLabel("课程名"));
//		studentAddPanel.add(courseNameTextField);
		studentAddPanel.add(new JLabel("成绩"));
		studentAddPanel.add(studentGradeTextField);
		studentAddPanel.add(confirmButton);
		return studentAddPanel;
	}

	public CourseControllerListener getCourseControllerListener() {
		return courseControllerListener;
	}

	public void setCourseControllerListener(CourseControllerListener courseControllerListener) {
		this.courseControllerListener = courseControllerListener;
	}

	public JButton getConfirmButton() {
		return confirmButton;
	}

	public void setConfirmButton(JButton confirmButton) {
		this.confirmButton = confirmButton;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public JTextField getStudentIdTextField() {
		return studentIdTextField;
	}

	public void setStudentIdTextField(JTextField studentIdTextField) {
		this.studentIdTextField = studentIdTextField;
	}

	public JTextField getStudentNoTextField() {
		return studentNoTextField;
	}

	public void setStudentNoTextField(JTextField studentNoTextField) {
		this.studentNoTextField = studentNoTextField;
	}

	public JTextField getStudentNameTextField() {
		return studentNameTextField;
	}

	public void setStudentNameTextField(JTextField studentNameTextField) {
		this.studentNameTextField = studentNameTextField;
	}

	
	public JRadioButton getRadioMan() {
		return radioMan;
	}

	public void setRadioMan(JRadioButton radioMan) {
		this.radioMan = radioMan;
	}

	public JRadioButton getRadioFemal() {
		return radioFemal;
	}

	public void setRadioFemal(JRadioButton radioFemal) {
		this.radioFemal = radioFemal;
=======

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import course.controller.CourseControllerListener;
import course.po.Student;

public class StudentDialog extends JDialog{
	private static final long serialVersionUID = -421235125631385670L;
	private CourseControllerListener  courseControllerListener;
	private JButton confirmButton;
	private JPanel studentAddPanel;
	private Student student;
	private JTextField studentIdTextField;
	private JTextField studentNoTextField;
	private JTextField  studentNameTextField;
	private JTextField studentSexTextField;
	private JTextField  studentAgeTextField;
	private JTextField  studentMajorTextField;
	private JTextField studentClassNoTextField;
	private JTextField courseIdTextField;
	private JTextField  courseNameTextField;
	private JTextField  studentGradeTextField;
	
	public StudentDialog(StudentJPanel owner, String title, Student student) {
		this.courseControllerListener = owner.getControllerListener();
		this.courseControllerListener.setStudentAddDialog(this);
		this.setTitle(title);
		this.student = student;
		this.add(getStudentAddPanel());
		this.setModal(true); // 设有模
		this.setSize(370, 530);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setVisible(true);
		this.validate();
	}

	public void closeCurrentDialog() {
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

	}

	/**
	 * 添加/修改表单面板
	 * 
	 * @return
	 */
	private JPanel getStudentAddPanel() {
		studentAddPanel = new JPanel();
		studentAddPanel.setBackground(Color.orange);
		if ("添加学生".equals(this.getTitle())) {
			studentIdTextField = new JTextField(30);
			studentNoTextField = new JTextField(30);
			studentNameTextField = new JTextField(30);
			studentSexTextField = new JTextField(30);
			studentAgeTextField = new JTextField(30);
			studentMajorTextField = new JTextField(30);
			studentClassNoTextField = new JTextField(30);
			courseIdTextField = new JTextField(30);
			studentGradeTextField = new JTextField(30);
			confirmButton = new JButton("确定添加");
			confirmButton.setActionCommand("addStudentPost"); // 添加学生
		} else {
			studentIdTextField = new JTextField(String.valueOf(student.getStuId()), 30);
			studentNoTextField = new JTextField(student.getStuNo(), 30);
			studentNameTextField = new JTextField(student.getStuName(), 30);
			studentSexTextField = new JTextField(student.getStuSex(), 30);
			studentAgeTextField = new JTextField(String.valueOf(student.getStuAge()), 30);
			studentMajorTextField = new JTextField(student.getStuMajor(), 30);
			studentClassNoTextField = new JTextField(String.valueOf(student.getStuClassNo()), 30);
			courseIdTextField =  new JTextField(String.valueOf(student.getCourse().getCouId()), 30);
			studentGradeTextField = new JTextField(String.valueOf(student.getStuGrade()), 30);
			confirmButton = new JButton("确定修改");
			confirmButton.setActionCommand("updateStudentPost"); // 修改学生
		}
		confirmButton.addActionListener( courseControllerListener);
		studentAddPanel.add(new JLabel("编号"));
		studentAddPanel.add(studentIdTextField);
		studentAddPanel.add(new JLabel("学号"));
		studentAddPanel.add(studentNoTextField);
		studentAddPanel.add(new JLabel("姓名"));
		studentAddPanel.add(studentNameTextField);
		studentAddPanel.add(new JLabel("性别"));
		studentAddPanel.add(studentSexTextField);
		studentAddPanel.add(new JLabel("年龄"));
		studentAddPanel.add(studentAgeTextField);
		studentAddPanel.add(new JLabel("专业"));
		studentAddPanel.add(studentMajorTextField);
		studentAddPanel.add(new JLabel("班级"));
		studentAddPanel.add(studentClassNoTextField);
		studentAddPanel.add(new JLabel("课程编号"));
		studentAddPanel.add(courseIdTextField);
//		studentAddPanel.add(new JLabel("课程名"));
//		studentAddPanel.add(courseNameTextField);
		studentAddPanel.add(new JLabel("成绩"));
		studentAddPanel.add(studentGradeTextField);
		studentAddPanel.add(confirmButton);
		return studentAddPanel;
	}

	public CourseControllerListener getCourseControllerListener() {
		return courseControllerListener;
	}

	public void setCourseControllerListener(CourseControllerListener courseControllerListener) {
		this.courseControllerListener = courseControllerListener;
	}

	public JButton getConfirmButton() {
		return confirmButton;
	}

	public void setConfirmButton(JButton confirmButton) {
		this.confirmButton = confirmButton;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public JTextField getStudentIdTextField() {
		return studentIdTextField;
	}

	public void setStudentIdTextField(JTextField studentIdTextField) {
		this.studentIdTextField = studentIdTextField;
	}

	public JTextField getStudentNoTextField() {
		return studentNoTextField;
	}

	public void setStudentNoTextField(JTextField studentNoTextField) {
		this.studentNoTextField = studentNoTextField;
	}

	public JTextField getStudentNameTextField() {
		return studentNameTextField;
	}

	public void setStudentNameTextField(JTextField studentNameTextField) {
		this.studentNameTextField = studentNameTextField;
	}

	public JTextField getStudentSexTextField() {
		return studentSexTextField;
	}

	public void setStudentSexTextField(JTextField studentSexTextField) {
		this.studentSexTextField = studentSexTextField;
>>>>>>> refs/remotes/origin/master
	}

	public JTextField getStudentAgeTextField() {
		return studentAgeTextField;
	}

	public void setStudentAgeTextField(JTextField studentAgeTextField) {
		this.studentAgeTextField = studentAgeTextField;
	}

	public JTextField getStudentMajorTextField() {
		return studentMajorTextField;
	}

	public void setStudentMajorTextField(JTextField studentMajorTextField) {
		this.studentMajorTextField = studentMajorTextField;
	}

	public JTextField getStudentClassNoTextField() {
		return studentClassNoTextField;
	}

	public void setStudentClassNoTextField(JTextField studentClassNoTextField) {
		this.studentClassNoTextField = studentClassNoTextField;
	}

	public JTextField getStudentGradeTextField() {
		return studentGradeTextField;
	}
	

	public JTextField getCourseIdTextField() {
		return courseIdTextField;
	}

	public void setCourseIdTextField(JTextField courseIdTextField) {
		this.courseIdTextField = courseIdTextField;
	}


	public void setStudentGradeTextField(JTextField studentGradeTextField) {
		this.studentGradeTextField = studentGradeTextField;
	}

	public void setStudentAddPanel(JPanel studentAddPanel) {
		this.studentAddPanel = studentAddPanel;
	}
	
}
